﻿using System;

namespace DotNetCommon.Validate.Annotations;

/// <summary>
/// 必须为null, 示例:
/// <code>
/// [VMustBeNull]
/// public int? Age { get; set; }
/// 
/// [VMustBeNull]
/// public string OtherInfo { get; set; }
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class VMustBeNullAttribute(string errorMessage = null) : Attribute, IValidateAction
{
    public string ErrorMessage { get; internal set; } = errorMessage;

    public void Action(IValidateContext ctx)
    {
        ValidateExtensions.MustBeNullInternal(ctx, ErrorMessage);
    }
}
